﻿using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;

using SixLottery.Core;
using SixLottery.Helpers;
using SixLottery.Models;
using System;

namespace SixLottery.Common
{
    /// <summary>
    /// Summary description for CommonHelper
    /// </summary>
    public static class CommonHelper
    {
        public static Member GetCurrentMember()
        {
            Member member = new Member() { UserName = "", Password = "", Level = (int)MemberLevelType.Guest };
            HttpCookie cookie = HttpContext.Current.Request.Cookies["darrenbo"];
            if (cookie == null)
            {
                return member;
            }
            else
            {
                try
                {
                    string value = SecurityHelper.DiscuzAuthcodeDecode(cookie.Value, SecurityHelper.Key);
                    NameValueCollection nv = System.Web.HttpUtility.ParseQueryString(value);
                    string name = nv["name"];
                    string pwd = nv["pwd"];
                    int level = int.Parse(nv["level"]);

                    member.UserName = name;
                    member.Password = pwd;
                    member.Level = level;

                    return member;

                }
                catch (Exception)
                {
                    return member;
                }
            }
        }
    } 
}